package com.heima.article.service.impl;


import com.heima.apis.behavior.IBehaviorClient;
import com.heima.article.service.ReadCountService;
import com.heima.model.behavior.dtos.ReadCountDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.utils.thread.ApThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author yht
 * @date 2022/1/16 13:32
 */
@Service
@Transactional
public class ReadCountServiceImpl implements ReadCountService {

    @Autowired
    private IBehaviorClient iBehaviorClient;
    @Override
    public ResponseResult readCount(ReadCountDto dto) {
        Integer id = ApThreadLocalUtils.getUser().getId();
        dto.setUserId(Long.parseLong(String.valueOf(id)));
        ResponseResult responseResult = iBehaviorClient.readCount(dto);
        if(responseResult.getCode()!=200){
            ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"远程调用失败");
        }
        return responseResult;
    }
}
